package com.ehotting.edsta.mqbd.signal.netty.service;

import com.ehotting.eaf.core.utils.AssertUtils;
import com.ehotting.edsta.mqbd.signal.api.bean.MqSignalTcpData;
import com.ehotting.edsta.mqbd.signal.api.domain.netty.CallSimulateRequest;
import com.ehotting.edsta.mqbd.signal.api.domain.netty.StopSimulateRequest;
import com.ehotting.mqbd.api.MqDataStateConstants;
import com.ehotting.mqbd.api.bean.MQDataAble;
import com.ehotting.mqbd.api.bean.MsgStateBean;
import com.ehotting.mqbd.api.enums.MsgStateEnum;
import com.ehotting.mqbd.api.exception.SuspendCurrentQueueMomentException;
import com.ehotting.mqbd.core.manager.AgentLinkManager;
import com.ehotting.mqbd.core.manager.MsgStateHandlerAble;
import com.ehotting.mqbd.core.manager.MsgStateManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SiMsgStateHandler implements MsgStateHandlerAble {

    public static Logger logger = LoggerFactory.getLogger(SiMsgStateHandler.class);

    @Autowired
    private MsgStateManager msgStateManager;

    @Override
    public void handleCancel(MQDataAble data) {
        MqSignalTcpData tcpData = (MqSignalTcpData) data;
        logger.info("tcpData.getRequest().getClass():{}",tcpData.getRequest());
        if(tcpData.getRequest() instanceof StopSimulateRequest){
            logger.info("Start msgStateManager.cancel({})",tcpData.getAgentId());
            Integer size = msgStateManager.cancel(tcpData.getAgentId());
            logger.info("Finish msgStateManager.cancel({}),size:{}",tcpData.getAgentId(),size);
        }
    }

    @Override
    public void handleDelete(String agentId) {
        msgStateManager.deleteByAgentIdAndSolving(agentId);
    }

}
